{#
# This file is part of Zenodo.
# Copyright (C) 2015, 2016 CERN.
#
# Zenodo is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Zenodo is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Zenodo; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307, USA.
#
# In applying this license, CERN does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.
#}

{% extends "zenodo_theme/page.html" %}

{% set title = config.THEME_SITENAME + " - Research. Shared." %}

{%- from "zenodo_records/macros/accessright.html" import accessright_label -%}
{%- from "zenodo_records/macros/objecttype.html" import objecttype_label -%}
{%- from "zenodo_records/macros/authors.html" import authors -%}

{%- block page_body %}

<!-- Featured communities -->
{% if featured_communities %}
<div style="background-color: aliceblue; margin-top: -20px;">
<div class="container body-container">

  <div class="row">
    <div class="col-sm-8 col-xs-12">
      {% if config.ZENODO_FRONTPAGE_FEATURED_TITLE %}
        <h2>{{ config.ZENODO_FRONTPAGE_FEATURED_TITLE }} related communities</h2>
      {% else %}
        <h2>Featured communities</h2>
        {% endif %}
    </div>
    <div class="col-sm-4 hidden-xs">
      <span class="pull-right" style="margin-top: 30px;">
        <small><a href="{{ url_for('zenodo_support.support')}}">{{_('Need help uploading? Contact us')}}</a></small>
      </span>
    </div>
    <div class="col-xs-12 hidden-sm hidden-md hidden-lg">
      <small><a href="{{ url_for('zenodo_support.support')}}">{{_('Need help uploading? Contact us')}}</a></small>
    </div>
  </div>
  <div class="row">
    <div class="col-md-12">

    <div id="carousel-featured-communities" class="carousel slide" data-interval="10000" data-ride="carousel">
      <!-- Indicators -->
      <!-- <ol class="carousel-indicators">
        {% for _ in featured_communities %}
          <li data-target="#carousel-featured-communities" data-slide-to="{{loop.index0}}" class="{{ 'active' if loop.first else '' }}"></li>
        {% endfor %}
      </ol> -->

      <!-- Wrapper for slides -->
      <div class="carousel-inner" role="listbox">
        {% for comm in featured_communities %}
          {% set upload_url = url_for('invenio_deposit_ui.new', c=comm.id) %}
          {% set community_url = url_for('invenio_communities.detail', community_id=comm.id) %}
          <div class="item {{ 'active' if loop.first else '' }}">
            <div class="container">
              <div class="row" style="height: 200px">
                <!-- left spacing -->
                <div class="col-xs-1 hidden-xs"></div>
                <!-- community logo -->
                <div class="col-sm-2 col-xs-6">
                  <img class="img-responsive" src="{{ comm.logo_url }}">
                </div>
                <!-- community content -->
                <div class="col-sm-8 col-xs-10">
                  <div class="row">
                    <div class="col-md-8 col-xs-12 record-elem">
                      <h4><a href="{{ community_url }}">{{ comm.title }}</a></h4>
                    </div>
                    <div class="col-md-4 hidden-sm hidden-xs">
                      <div class="pull-right">
                        <a href="{{ community_url }}" class="btn btn-sm btn-default">{{_('Browse')}}</a>
                        <a href="{{ upload_url }}" class="btn btn-sm btn-success"><i class="fa fa-upload"></i> {{_('New upload')}}</a>
                      </div>
                    </div>
                    <div class="col-xs-12 hidden-lg hidden-md">
                      <div>
                        <a href="{{ community_url }}" class="btn btn-sm btn-default">{{_('Browse')}}</a>
                        <a href="{{ upload_url }}" class="btn btn-sm btn-success"><i class="fa fa-upload"></i> {{_('New upload')}}</a>
                      </div>
                    </div>

                  </div>
                  <div class="row">
                    <div class="col-md-12">
                      <p>{{ comm.description|striptags|truncate(300) }}</p>
                      {%- if comm.owner.profile.username %}
                      <strong>Curated by: </strong>{{ comm.owner.profile.username }}
                      {% endif %}
                    </div>
                  </div>
                </div>
                <!-- right spacing -->
                <div class="col-xs-1 hidden-xs"></div>
              </div>
            </div>
          </div>
        {% endfor %}
      </div>

      <!-- Controls -->
      <a class="left carousel-control" href="#carousel-featured-communities" role="button" data-slide="prev" style="background-image: none; width: 5%;">
        <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
        <span class="sr-only">Previous</span>
      </a>
      <a  class="right carousel-control" href="#carousel-featured-communities" role="button" data-slide="next" style="background-image: none; width: 5%;">
        <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
      </a>
    </div>
  </div>
  </div>
</div>
</div>
{% endif %}

<!-- Featured records -->
{% if featured_records %}
<div style="background-color: whitesmoke;">
  <div class="container body-container">

  <div class="row">
    <div class="col-sm-8 col-xs-12">
      {% if config.ZENODO_FRONTPAGE_FEATURED_TITLE %}
        <h2>Featured uploads related to {{ config.ZENODO_FRONTPAGE_FEATURED_TITLE }}</h2>
      {% else %}
        <h2>Featured uploads</h2>
      {% endif %}
    </div>
    <div class="col-sm-4 hidden-xs">
      <span class="pull-right" style="margin-top: 30px;">
        <small><a href="{{ url_for('zenodo_support.support')}}">{{_('Want your dataset featured? Contact us')}}</a></small>
      </span>
    </div>
    <div class="col-xs-12 hidden-sm hidden-md hidden-lg">
      <small><a href="{{ url_for('zenodo_support.support')}}">{{_('Want your dataset featured? Contact us')}}</a></small>
    </div>
  </div>
  <div class="row">
    {% for fr_recid, fr in featured_records[:3] %}
      {%- set publication_date = fr.publication_date|from_isodate -%}
      {%- set record_version = fr.version -%}
      {%- set creation_date = fr._created|from_isodatetime -%}
      {%- set embargo_date = fr.embargo_date|from_isodate -%}
      {%- set object_type = fr.resource_type|objecttype %}
      {%- set record_url = url_for('invenio_records_ui.recid', pid_value=fr['recid']) %}

      <div class="col-md-4">
        <div class="row record-elem">
          <div class="col-xs-12">
            <div class="pull-left">
              <span class="label label-info" data-toggle="tooltip" title="{{_('Publication date')}}">{{ publication_date|dateformat(format='long') }}{{ (' (v' ~ record_version ~ ')') if record_version else '' }}</span>
              {{ objecttype_label(object_type, lang=current_i18n.language) }}
              {{ accessright_label(fr.access_right, embargo_date=embargo_date) }}
            </div>
            <br />
            <h4><a href="{{ record_url }}">{{fr.title}}</a></h4>
            <p>{{ authors(fr.creators) }}</p>
            <p class="hidden-xs"><a href="{{record_url}}">{{ fr.description|striptags|truncate(200) }}</a></p>
            <small class="text-muted hidden-xs">
              {% trans user=userprofile, date=creation_date|dateformat('long') %}Uploaded on {{date}}{% endtrans %}
            </small>
          </div>
      </div>
    </div>
    {% endfor %}
  </div>
  {% if config.ZENODO_FRONTPAGE_FEATURED_COMMUNITY %}
    <div class="row">
      <div class="col-md-4 hidden-xs"></div>
      <div class="col-md-4">
        <a href="{{ url_for('invenio_communities.search', community_id=config['ZENODO_FRONTPAGE_FEATURED_COMMUNITY']) }}" class="btn btn-default">Browse {{ config.ZENODO_FRONTPAGE_FEATURED_TITLE }} related research</a>
      </div>
      <div class="col-md-4 hidden-xs"></div>
    </div>
  {% endif %}
</div>
</div>
{% endif %}

<div class="container body-container" style="margin-top: 20px;">
  <!-- Recent records -->
  <div class="row">
    <div class="col-md-8">
      <div class="row">
        <div class="col-xs-12">
          <h2>{{_('Recent uploads')}}</h2>
        </div>
      </div>
      {%- for r in records %}
        {%- set publication_date = r.publication_date|from_isodate -%}
        {%- set record_version = (r.version or (r.relations.version[0].index + 1)) if r.conceptrecid else None -%}
        {%- set creation_date = r._created|from_isodatetime -%}
        {%- set embargo_date = r.embargo_date|from_isodate -%}
        {%- set object_type = r.resource_type|objecttype %}
        {%- set record_url = url_for('invenio_records_ui.recid', pid_value=r['recid']) %}
        <div class="row record-elem">
          <div class="col-xs-12">
            <div class="pull-right view-record hidden-xs">
              <a href="{{ record_url }}" class="btn btn-default">{{_('View')}}</a>
            </div>
            <div class="pull-left">
              <span class="label label-info" data-toggle="tooltip" title="{{_('Publication date')}}">{{ publication_date|dateformat(format='long') }}{{ (' (v' ~ record_version ~ ')') if record_version else '' }}</span>
              {{ objecttype_label(object_type, lang=current_i18n.language) }}
              {{ accessright_label(r.access_right, embargo_date=embargo_date) }}
            </div>
            <br />
            <h4><a href="{{ record_url }}">{{r.title}}</a></h4>
            <p>{{ authors(r.creators) }}</p>
            <p class="hidden-xs"><a href="{{record_url}}">{{ r.description|striptags|truncate(300) }}</a></p>
            <small class="text-muted hidden-xs">
              {% trans user=userprofile, date=creation_date|dateformat('long') %}Uploaded on {{date}}{% endtrans %}
            </small>
            {%- if r.relations.version[0].count|d(1) > 1 %}
              <p class="text-muted"><a href="{{ url_for('invenio_search_ui.search', q=('conceptrecid:' ~ r.conceptrecid), all_versions=True, sort='-version') }}"><small><i>{{ r.relations.version[0].count - 1 }} more version(s) exist for this record</i> </small></a></p>
            {% endif %}
          </div>
        </div>
        {%- if not loop.last %}
        <hr class="hidden-xs" />
        {%- else%}
        <p class="text-center"><a class="btn btn-default" href="{{url_for('invenio_search_ui.search')}}">More</a></p>
        {%- endif %}
      {%- endfor %}
    </div>
    <div class="col-md-4">
      <div class="well">
        <div class="row">
          <div class="col-xs-12 col-sm-12 col-lg-12 ">
            <h4>Need help?</h4>
            <div style="padding-bottom: 10px;">
              <a href="{{ url_for('zenodo_support.support')}}" class="btn btn-block btn-default">Contact us</a>
            </div>
            <p>Zenodo prioritizes all requested related to the COVID-19 outbreak.</p>
            <p>We can help with:</p>
            <ul>
              <li>Uploading your research data, software, preprints, etc.</li>
              <li>One-on-one with Zenodo supporters.</li>
              <li>Quota increases beyond our default policy.</li>
              <li>Scripts for automated uploading of larger datasets.</li>
            </ul>
          </div>
        </div>
      </div>
      <div class="well">
        <h4>Why use {{config.THEME_SITENAME}}?</h4>
        {% include "zenodo_frontpage/benefits.html" %}
      </div>

      <div class="hidden-xs">
        <a class="twitter-timeline" href="https://twitter.com/ZENODO_ORG" data-widget-id="331751059422855169"></a>
      </div>
    </div>
  </div>
</div>
{%- endblock page_body %}

{% block javascript %}
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
{{ super() }}
<script type="text/javascript">
$(function () {
  $('[data-toggle="tooltip"]').tooltip();
});
</script>
{% endblock javascript %}
